
<template tag="以下文档内容为hycli自动生成">
  <el-dialog
    v-model="conf.visible"
    v-if="conf.visible" 
    :title="title"
   :width="conf.width"
    draggable
     top="10vh" 
    :close-on-click-modal="false"
  >
  <el-form :model="form"  ref="form" :rules="rules_aaasz">
    <el-row>
    <el-col :span="12">
    <!-- {"index":35,"raw":"staff_id","name":"staff_id","cname":"StaffId","type":{"raw":"number(10)","name":"number","len":10,"dlen":0},"defValue":"","allowNull":false,"constraints":["q","le","c","u","v","sl(staff_info)","@change(name:name)"],"desc":{"raw":"员工","name":"员工"}} -->
     <!--员工 下拉控件 -->
    <el-form-item prop="staff_id" label="员工" label-width="100px" label-position="right">
      <el-select   @change="onChange_staff_id(form.staff_id,'staff_info')" v-model="form.staff_id" style="width: 100%" filterable clearable
        placeholder="请选择员工" >
        <el-option v-for="item in staff_idList" :key="item.value" :label="item.name" :value="item.value" />
      </el-select>
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":36,"raw":"name","name":"name","cname":"Name","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":false,"constraints":["q","l","le","c","u","v","DN","#like"],"desc":{"raw":"姓名","name":"姓名"}} -->
    <!--姓名 输入控件 -->
    <el-form-item prop="name" label="姓名" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.name"  maxlength="32" 
      :rows="0"  placeholder="请输入姓名"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":37,"raw":"user_name","name":"user_name","cname":"UserName","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":false,"constraints":["UNQ(unq_sso_user,2)","q","l","le","c","u","v"],"desc":{"raw":"登录名","name":"登录名"}} -->
    <!--登录名 输入控件 -->
    <el-form-item prop="user_name" label="登录名" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.user_name"  maxlength="32" 
      :rows="0"  placeholder="请输入登录名"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":38,"raw":"mobile","name":"mobile","cname":"Mobile","type":{"raw":"varchar(12)","name":"varchar","len":12,"dlen":0},"defValue":"","allowNull":true,"constraints":["q","l","le","c","u","v"],"desc":{"raw":"手机号","name":"手机号"}} -->
    <!--手机号 输入控件 -->
    <el-form-item prop="mobile" label="手机号" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.mobile"  maxlength="12" 
      :rows="0"  placeholder="请输入手机号"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":39,"raw":"password","name":"password","cname":"Password","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":false,"constraints":["c","tp(password,c-u)","v"],"desc":{"raw":"密码","name":"密码"}} -->
      <!--密码 密码控件 -->
    <el-form-item prop="password" label="密码" label-width="100px" label-position="right">
      <el-input clearable type="password" show-password style="width: 100%" v-model="form.password"
        maxlength="32" placeholder="请输入密码" />
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":42,"raw":"status","name":"status","cname":"Status","type":{"raw":"tinyint(1)","name":"tinyint","len":1,"dlen":0},"defValue":"1","allowNull":false,"constraints":["l","le","c","u","v","sl","tp(radio,c-u)","tp(switch,l)"],"desc":{"raw":"状态 0:正常 1锁定 2禁用","name":"状态"}} -->
    <el-form-item prop="status" label="状态" label-width="100px" label-position="right">
      <el-radio-group v-model="form.status"   >
        <el-radio-button v-for="item in statusList" :key="item.value" :label="item.value" >
            {{item.name}}
        </el-radio-button>
      </el-radio-group>
      <el-tooltip raw-content="true" content="状态 0:正常 1锁定 2禁用" placement="bottom" effect="light">
      <i class="form_item_info fa fa-info-circle"  aria-hidden="true" />
      </el-tooltip>
    </el-form-item>
    </el-col>
    </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="hide" icon="close">取消</el-button>
        <el-button type="primary" @click="save" icon="select">提交</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import rtext from "@/views/cmpnts/rtext.vue"
export default {
  components: {
    rtext
},
  data() {
    return {
      conf: {
        title:"添加用户",
        visible: false,
        width:"60%",
        uploadPath:this.$theia.env.join("/file/upload"),
      },
rules_aaasz:{
    staff_id:[{required:true,message:"请输入员工",trigger: 'blur'}],
    name:[{required:true,message:"请输入姓名",trigger: 'blur'}],
    user_name:[{required:true,message:"请输入登录名",trigger: 'blur'}],
    mobile:[{required:false,message:"请输入手机号",trigger: 'blur'}],
    password:[{required:true,message:"请输入密码",trigger: 'blur'}],
    status:[{required:true,message:"请输入状态",trigger: 'blur'}],
  },
    form:{
        staff_id:"",
        name:"",
        user_name:"",
        mobile:"",
        password:"",
        status:"",
    },
    staff_idList:[],
    statusList:[],
    }
  },
  methods: {
    show(fm = {}) {
      this.title = fm.$title || this.title
      this.conf.visible = true;
      this.loadEnums_aaasz()
      let local = {}
      let cache = Object.assign(local,fm)
      this.form = Object.assign(cache,this.$route.params)
      this.onChange_staff_id(this.$route.params["staff_id"]||this.form["staff_id"],"staff_info")
    },
    save(){
      this.$refs.form.validate((v=>{
          if(v) this.onSave()
      }))
    },
    onSave(){
        let that = this
        let postForm = Object.assign({},this.form)
        postForm.password = this.$theia.crypto.md5(this.form.password)
        //保存数据
        this.$theia.http.post("/sso/user/account",postForm).then(res=>{
            that.$notify.success({title: '成功',message: '用户账户保存成功',duration:5000})
            that.hide()
            that.$theia.enum.clear("user_account")
            that.$emit("onsaved")
        }).catch(res=>{
            let code = ((res||{}).response||{}).status||0
            let msg= `用户账户保存失败(${code})`
            msg = code == 909? msg+"数据重复，请修改后重试":msg
            that.$notify.error({title: '失败',message:msg,duration:5000})
        })
    },
    hide() {
      this.conf.visible = false;
      this.$refs.form.resetFields();
    },
    onUploadSuccess(response){
    },
    onChange_staff_id(val,tp){
      //添加联动
      let that = this
      if(tp){
        let lst= this.$theia.enum.get(tp)
        var hasValues = {}
        lst.forEach(el => {
          if(el.value == val)
          if (!that.form.name || that.form._name == that.form.name) {
            hasValues.name = true
            that.form.name = el.name
            that.form._name = el.name
          }
        });
        if(!hasValues.name){
          that.form.name = ""
          that.form._name = ""
        }
      }
    },
    loadEnums_aaasz(){
        //员工
        this.staff_idList = this.$theia.enum.get("staff_info","","" ,false,"")
        //状态
        this.statusList = this.$theia.enum.get("status","","" ,false,"")
    },

},
}
</script>

<style scoped>
.avatar-uploader .avatar {
  width: 80px;
  height: 80px;
  display: block;
}
.form_item_info{
  margin-left: 4px;
  color:#999;
}
.form_item_info:hover{
  cursor: pointer;
  font-weight: 500;
  color:#333;
}
</style>